package sing.core.ext.util

import android.text.TextUtils
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.widget.TextView
import android.widget.Toast
import sing.core.R
import sing.core.base.appContext


fun String.showShort() {
    short(this)
}

var toast: Toast? = null // 只创建一次
fun short(msg: String) {
    try {
        if (toast == null) {
            toast = Toast(appContext)
        }
        toast!!.setGravity(Gravity.BOTTOM, 0, appContext.screenHeight / 5)
        toast!!.duration = Toast.LENGTH_SHORT
        val root: View = LayoutInflater.from(appContext).inflate(R.layout.layout_toast, null)
        toast!!.view = root

        if (!TextUtils.isEmpty(msg)) {
            val tv = toast!!.view?.findViewById<TextView>(R.id.tv_txt)
            tv?.text = msg
            toast!!.show()
        }
    } catch (e: Exception) {
    }
}

